export default class extends think.Service {
 async list(option: SqlOptionFace) {
    let { page = 1, size = 10, where={}, order, field } = option;
    const $model = think.model("ai_img");
    const pk = $model.pk;
    if (think.isEmpty(field)) {
      field =
        pk +
        ",member_id,user_img,out_img,text,style,status,taskId,type,remarks,is_delete,create_time,update_time,delete_time";
    }
    if (think.isEmpty(order)) {
      order = {
        [pk]: "DESC",
        update_time: "DESC",
      };
    }

 const data= await $model
      .field(field)
      .order(order)
      .where(where)
      .page(page, size)
      .countSelect();

      
      data.data =data.data.map(v=>{
        if(v.out_img){
          v.out_img= v.out_img.split(',').map(v=>process.env.BASE_IMG_URL+v).join(',')
        }
        return v
      })
      return data
  }
 async add(data: AiimgCommunityFace) {
    const $model = think.model("ai_img");
    const pk = $model.pk;
    data.create_time = think.formatter();
    const id = await $model.add(data);
 
    if (think.isEmpty(id)) {
      return id;
    }
    data[pk] = id;
    return data;
  }
  edit(data: AiimgCommunityFace) {
    const $model = think.model("ai_img");
    const pk = $model.pk;
    data.update_time = think.formatter();
    $model
      .where({
        [pk]: data[pk],
      })
      .update(data);

    return data;
  }
  async info(id: number) {
    const $model = think.model("member");
    const $pk = $model.pk;
    const info = await $model.where({ [$pk]: id }).find();
    return info;
  }
  update(data: AiimgCommunityFace) {
    const $model = think.model("ai_img");
    const $pk = $model.pk;
    if (!data[$pk]) {
      return;
    }
    data.update_time = think.formatter();
    const datas = $model.where({ [$pk]: data[$pk] }).update(data);
    return datas;
  }
}
